<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="客户名称" prop="purchaserName">
        <el-input v-model="queryParams.purchaserName" placeholder="请输入客户名称" clearable
          style="width: 240px" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="登录账号" prop="username">
        <el-input v-model="queryParams.username" placeholder="请输入登录账号" clearable
          style="width: 240px" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="客户类型" prop="mold">
        <el-select v-model="queryParams.mold" placeholder="客户类型" clearable style="width: 240px">
          <el-option v-for="dict in dict.type.purchaser_certified_mold" :key="dict.value"
            :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="账号状态" prop="payStatus">
        <el-select v-model="queryParams.payStatus" placeholder="付款状态" clearable
          style="width: 240px">
          <el-option v-for="dict in dict.type.order_pay_status" :key="dict.value"
            :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="审核状态" prop="applyStatus">
        <el-select v-model="queryParams.applyStatus" placeholder="资质审核状态" clearable
          style="width: 240px">
          <el-option v-for="dict in dict.type.purchaser_apply_status" :key="dict.value"
            :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker v-model="dateRange" style="width: 240px" value-format="yyyy-MM-dd"
          type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索
        </el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini"
          @click="handleEditTable(undefined)" v-hasPermi="['system:role:add']" :disabled="single">新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single"
          @click="handleEditTable" v-hasPermi="['system:role:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['purchaser:purchaser:export']">导出</el-button>
      </el-col>
      <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
        @click="deleteClick" v-hasPermi="['purchaser:purchaser:remove']">删除</el-button>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns">
      </right-toolbar>
    </el-row>

    <el-table border v-loading="loading" :data="orderList"
      @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" />
      <el-table-column :label="columns[0].label" :prop="columns[0].prop"
        :show-overflow-tooltip="true" :width="columns[0].width" v-if="columns[0].visible"
        align="center" />
      <el-table-column :label="columns[1].label" :prop="columns[1].prop"
        :show-overflow-tooltip="true" :width="columns[1].width" v-if="columns[1].visible"
        align="center" />
      <el-table-column :label="columns[2].label" :prop="columns[2].prop"
        :show-overflow-tooltip="true" :width="columns[2].width" v-if="columns[2].visible"
        align="center" />
      <el-table-column :label="columns[3].label" :prop="columns[3].prop" align="center"
        :width="columns[3].width" v-if="columns[3].visible">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.purchaser_certified_mold" :value="scope.row.mold" />
        </template>
      </el-table-column>
      <el-table-column :label="columns[4].label" :prop="columns[4].prop" align="center"
        :width="columns[4].width" v-if="columns[4].visible">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.purchaser_apply_status" :value="scope.row.applyStatus" />
        </template>
      </el-table-column>
      <el-table-column :label="columns[5].label" align="center" :prop="columns[5].prop" :width="columns[5].width"></el-table-column>
      <el-table-column :label="columns[6].label" align="center" :prop="columns[6].prop" :width="columns[6].width"></el-table-column>
      <el-table-column :label="columns[7].label" align="center" :prop="columns[7].prop" :width="columns[7].width"></el-table-column>
      <el-table-column :label="columns[8].label" align="center" :prop="columns[8].prop" :width="columns[8].width">
      </el-table-column>
      <el-table-column label="操作" align="center" width="130" fixed="right">
        <template slot-scope="scope">
          <el-button type="text" v-hasPermi="['purchaser:purchaser:materials:applyStatus:edit']"
            v-show="scope.row.applyStatus=='WAIT_AUDIT'" @click="openExamineView(scope.row)" size="small">一键审核</el-button>
          <el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)"
            v-hasPermi="['purchaser:material:preview', 'purchaser:purchaser:business:edit', 'purchaser:purchaser:certified:material:list', 'purchaser:purchaser:member:edit', 'purchaser:purchaser:relevance:edit']">
            <span class="el-dropdown-link">
              <i class="el-icon-d-arrow-right el-icon--right"></i>更多
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="openPreview" icon="el-icon-circle-check"
                v-hasPermi="['purchaser:material:preview']">查看资质</el-dropdown-item>
              <el-dropdown-item command="openBusinessContent" icon="el-icon-circle-check"
                v-hasPermi="['purchaser:purchaser:business:edit']">经营范围</el-dropdown-item>
              <el-dropdown-item command="openHandleEditTable" icon="el-icon-grape"
                v-hasPermi="['purchaser:purchaser:member:edit']">登录管理</el-dropdown-item>
              <el-dropdown-item command="handleTemporaryPwd" icon="el-icon-grape"
                v-hasPermi="['purchaser:member:temporaryPwd']">临时密码</el-dropdown-item>
              <el-dropdown-item command="deleteHandle" icon="el-icon-delete"
                v-hasPermi="['purchaser:purchaser:remove']">删除信息</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize" @pagination="getList" />

    <!-- 资质 图片 审核 -->
    <el-dialog v-dialogDragWidth v-dialogDragHeight v-dialogDrag title="资质 图片 审核"
      :visible.sync="openPromotionFlag" width="62%">
      <div class="list">
        <div v-for="(item,index) in imgForm" :key="index" class="item">
          <el-image :src="item.filePath" :preview-src-list="item.srcList">
          </el-image>
          <!-- <img :src="item.filePath" alt="" @click="item.imgEnlarge = true">
          <img :src="item.filePath" alt="" class="imgEnlarge" v-show="item.imgEnlarge"
            @click="item.imgEnlarge = false"> -->
          <div class="status">
            <p>当前状态：{{item.status}}</p>
            <el-select v-model="item.imgApplyStatus" placeholder="资质审核状态" clearable>
              <el-option v-for="dict in dict.type.purchaser_apply_status" :key="dict.value"
                :label="dict.label" :value="dict.value" />
            </el-select>
            <textarea placeholder="描述信息..." v-model="item.textarea" cols="30" rows="2"></textarea>
            <el-button @click="SubmitExamine(item)"> 确 定 </el-button>
          </div>
        </div>
      </div>
    </el-dialog>

    <!-- 预览客户上传的资质 -->
    <el-dialog v-dialogDrag title="预览资质" :visible.sync="previewMaterialVisble">
      <fieldset>
        <legend style="text-align:left">必选</legend>
        <el-table :data="previewMaterial.requireds" border style="width: 100%">
          <el-table-column prop="classificationName" label="名称" align="center"> </el-table-column>
          <el-table-column prop="filePath" label="资质图片" align="center">
            <template slot-scope="scope">
              <el-image v-if="scope.row.filePath" style="width: 40px" :src="scope.row.filePath"
                @click="clickOriginal(scope.row)">
              </el-image>
            </template>
          </el-table-column>
          <el-table-column prop="applyStatus" label="状态" align="center">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.purchaser_apply_status"
                :value="scope.row.applyStatus" />
            </template>
          </el-table-column>
          <el-table-column align="center">
            <template slot-scope="scope">
              <el-button @click="goForReview(scope.row)" size="small"
                v-if="scope.row.applyStatus==='WAIT_AUDIT'">
                去审核
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </fieldset>
      <fieldset>
        <legend style="text-align:left">可选</legend>
        <el-table :data="previewMaterial.optionals" border style="width: 100%">
          <el-table-column prop="classificationName" label="名称" align="center"> </el-table-column>
          <el-table-column prop="filePath" label="资质图片" align="center">
            <template slot-scope="scope">
              <el-image v-if="scope.row.filePath" style="width: 40px" :src="scope.row.filePath"
                @click="clickOriginal(scope.row)">
              </el-image>
            </template>
          </el-table-column>
          <el-table-column prop="applyStatus" label="状态" align="center">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.purchaser_apply_status"
                :value="scope.row.applyStatus" />
            </template>
          </el-table-column>
          <el-table-column align="center">
            <template slot-scope="scope">
              <el-button @click="goForReview(scope.row)" size="small"
                v-if="scope.row.applyStatus==='WAIT_AUDIT'">
                去审核
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </fieldset>
      <div slot="footer" class="dialog-footer">
        <!--
        <el-button type="primary" @click="previewMaterialVisble=false">关 闭</el-button>
        -->
      </div>
    </el-dialog>

    <!-- 去审核 -->
    <el-dialog v-dialogDrag :title="auditingTitle" :visible.sync="auditingVisible" width="70%">
      <div class="content">
        <userAvatar class="preview" :user="auditingFilePath"></userAvatar>
        <el-descriptions class="margin-top" :column="1" border v-if="auditingData.length">
          <el-descriptions-item v-for="(i,j) in auditingData" :key="j" :label="i.title">
            <el-input type="textarea" v-if="i.control==='input'||i.control==='textarea'"
              v-model="i.value" autosize resize="none">
            </el-input>
            <div v-if="i.control==='date'" style="display:flex;align-items:center;min-height:41px">
              <el-radio v-model="i.value.type" label="radio" v-if="i.brotherControl"
                @input="changeRadio(i)">
                {{i.brotherTitle}}
              </el-radio>
              <el-radio v-model="i.value.type" label="date" v-if="i.brotherControl"
                @input="changeRadio(i)">
                {{i.brotherLabel}}
              </el-radio>
              <el-date-picker v-model="i.value.value" value-format="yyyy-MM-dd" type="date"
                v-if="i.value.type==='date'">
              </el-date-picker>
            </div>
            <el-select v-model="i.value" v-if="i.control == 'select' && i.meta.type == 'select'">
              <el-option v-for="(metaI, metaJ) in i.meta.list" :key="metaJ" :label="metaI.key"
                :value="metaI.value">
              </el-option>
            </el-select>
            <el-select v-model="i.value" v-if="i.lineName == 'province'"
              @change="modifyAdministrative(i)">
              <el-option v-for="(metaI, metaJ) in administrativeProvince" :key="metaJ"
                :label="metaI.name" :value="metaI.id">
              </el-option>
            </el-select>
            <el-select v-model="i.value" v-if="i.lineName == 'city'"
              @change="modifyAdministrative(i)">
              <el-option v-for="(metaI, metaJ) in administrativeCity" :key="metaJ"
                :label="metaI.name" :value="metaI.id">
              </el-option>
            </el-select>
            <el-select v-model="i.value" v-if="i.lineName == 'county'"
              @change="modifyAdministrative(i)">
              <el-option v-for="(metaI, metaJ) in administrativeCounty" :key="metaJ"
                :label="metaI.name" :value="metaI.id">
              </el-option>
            </el-select>
          </el-descriptions-item>
        </el-descriptions>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="warning" v-if="currentMaterialRow.applyStatus == 'WAIT_AUDIT'"
          v-hasPermi="['purchaser:material:examine']" @click="materialVerify('REVIEW')">通过</el-button>
        <el-button type="primary" v-if="currentMaterialRow.applyStatus == 'WAIT_AUDIT'"
          v-hasPermi="['purchaser:material:examine']" @click="materialVerify('APPLY')">拒绝</el-button>
      </div>
    </el-dialog>

    <!-- 编辑登录账号 -->
    <el-dialog v-dialogDragWidth v-dialogDragHeight v-dialogDrag
      :visible.sync="businessRangeVisible2" width="600px">
      <el-form :inline="true" label-width="100px">
        <el-card shadow="always">
          <el-form-item label="修改密码：">
            <el-input v-model="modifyPassword" style="width:250px;margin-right:10px"></el-input>
          </el-form-item>
          <el-button type="primary" @click="clickBusiness2">修 改</el-button>
        </el-card>
        <el-card shadow="always">
          <el-form-item label="修改账号：">
            <el-input v-model="modifyAccount" style="width:250px;margin-right:10px"></el-input>
          </el-form-item>
          <!--
          <el-form-item label="修改手机号：">
            <el-input v-model="modifyPhone" style="width:250px;margin-right:10px"></el-input>
          </el-form-item>
          -->
          <el-form-item label="采购员：">
            <el-input v-model="buyerName" style="width:250px;margin-right:10px"></el-input>
          </el-form-item>
          <el-button type="primary" @click="clickBusiness3">修 改</el-button>
        </el-card>
      </el-form>
    </el-dialog>

    <!-- 打开临时密码对话框 -->
    <el-dialog v-dialogDragWidth v-dialogDragHeight v-dialogDrag title="临时登录密码"
      :visible.sync="openTemporaryPwdFlag" width="450px" append-to-body>
      <el-form ref="temporaryPwdForm" label-width="80px">
        <el-row>
          <el-col>
            <el-form-item label="登录账号" prop="username">
              <el-input v-model="currentRow.username" style="width:215px;margin-right:10px" readonly></el-input>
              <el-button id="copyUsername">复 制</el-button>
            </el-form-item>
            <el-form-item label="临时密码" prop="tmpPwd">
              <el-input v-model="temporaryPwd" style="width:130px;margin-right:10px" readonly></el-input>
              <el-button @click="refreshTemporaryPwd" v-hasPermi="['purchaser:member:temporaryPwd']">刷 新</el-button>
              <el-button id="copyTmpPwd">复 制</el-button>
            </el-form-item>
            <p style="color: orangered;">临时密码一分钟内有效</p>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>

    <!-- 经营范围 -->
    <el-dialog v-dialogDragWidth v-dialogDragHeight v-dialogDrag
      :visible.sync="businessRangeVisible" width="500px">
      <el-input type="textarea" ref="businessRange" autosize resize v-model="businessRange"> </el-input>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="clickBusiness">修 改</el-button>
        <el-button @click="businessRangeVisible = false">关 闭</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import userAvatar from './userAvatar.vue'
import { list, getPurchaserApplyList, examinePurchaserImg, deletePurchaserQualifications, changeAccount,
autoExamine, changePassword, updateBusiness} from "@/api/purchaser/purchaser";
import {updateDisabled, refreshTmpPwd} from "@/api/purchaser/member";
import { previewMaterials, materialExamine } from "@/api/purchaser/purchaserMaterial"
import { administrativeDivision } from '@/api/limitSale/promotionControlSale'
import ClipboardJS from 'clipboard'

export default {
  name: "LicenseQualificationReview",
  dicts: ["purchaser_certified_mold", "purchaser_apply_status"],
  components: { userAvatar },
  data () {
    return {
      // 遮罩层
      loading: true,
      openPromotionFlag: false,
      imgForm: [],
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单表格数据
      orderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层（数据权限）
      openDataScope: false,
      // 日期范围
      dateRange: [],
      // 列信息
      columns: [
        { key: 0, label: `客户名称`, prop: "purchaserName", width: 300, visible: true },
        { key: 1, label: `手机号码`, prop: "mobile", width: 150, visible: true },
        { key: 2, label: `采购员`, prop: "memberName", width: 200, visible: true },
        { key: 3, label: `客户类型`, prop: "goodsPrice", width: 100, visible: true, },
        { key: 4, label: `审核状态`, prop: "applyStatus", width: 100, visible: true },
        { key: 5, label: `省`, prop: "provinceName", width: 80, visible: true },
        { key: 6, label: `市`, prop: "cityName", width: 80, visible: true },
        { key: 7, label: `市`, prop: "countyName", width: 100, visible: true },
        { key: 8, label: `创建时间`, prop: "createTime", width: 160, visible: true }
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        purchaserName: '',
        username: '',
        mold: '',
        payStatus: '',
        applyStatus: '',
        paramMap: { applyStatus: 'APPLY,REAPPLY,MAKE_UP,WAIT_AUDIT,REVIEW,REFUSE' },
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        promotionPrice: [
          { required: true, message: "促销价格不能为空", trigger: "blur" }
        ],
        roleKey: [
          { required: true, message: "权限字符不能为空", trigger: "blur" }
        ],
        roleSort: [
          { required: true, message: "角色顺序不能为空", trigger: "blur" }
        ]
      },

      currentMaterialRow: {
        applyStatus: ''
      },
      previewMaterialVisble: false,
      previewMaterial: '',
      auditingVisible: false,
      auditingTitle: '',
      currentExamineMaterialId: undefined,
      auditingData: [],
      auditingFilePath: '',
      province: '',
      city: '',
      county: '',
      administrativeProvince: [],
      administrativeCity: [],
      administrativeCounty: [],
      failReason: '',

      businessRangeVisible2: false,

      openTemporaryPwdFlag: false,
      modifyPassword: '',
      modifyAccount: '',
      modifyPhone: '',
      buyerName: '',
      // 当前行数据
      currentRow: {
        username: ''
      },
      openTemporaryPwdFlag: false,
      temporaryPwd: undefined,

      businessRangeVisible: false,
      businessRange: undefined,
    }
  },
  created () {
    this.getList()
  },
  mounted() {
    const usernameClipboard = new ClipboardJS('#copyUsername', {
      text: trigger => {
        this.$notify({
          title: '成功',
          message: '登录账号已复制到剪切板，可粘贴。',
          type: 'success'
        })
        return this.currentRow.username
      }
    })
    usernameClipboard.on('error', e => {
      this.$message.error('登录账号复制失败')
    })

    const tmpPwdClipboard = new ClipboardJS('#copyTmpPwd', {
      text: trigger => {
        this.$notify({
          title: '成功',
          message: '临时密码已复制到剪切板，可粘贴。',
          type: 'success'
        })
        return this.temporaryPwd
      }
    })
    tmpPwdClipboard.on('error', e => {
      this.$message.error('临时密码复制失败')
    })
  },
  methods: {
    changeRadio (e) {
      if (e.value.type === 'radio') { e.value.value = true }
      if (e.value.type === 'date') { e.value.value = '' }
    },
    // 删除行
    deleteClick (row) {
      const ids = row.purchaserId || this.ids;
      this.$modal.confirm('确认删除吗？').then(function () {
        return deletePurchaserQualifications(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(function () {
        this.$modal.msgError("删除失败！")
      })
    },
    /** 查询订单列表 */
    getList () {
      this.loading = true;
      list(this.addDateRangeWithMap(this.queryParams, this.dateRange, "CreateTime")).then(response => {
        this.orderList = response.rows;

        this.total = response.total;
        this.loading = false;
      });
    },
    // 详情
    examineDetailsClick (val) {
      getPurchaserApplyList(val).then(res => {
        if (res.code === 200) {
          this.openPromotionFlag = true
          this.imgForm = res.data
          this.imgForm.forEach(ii => {
            //ii.filePath = 'https://www.xdyy100.com/wholesale' + ii.filePath
            //ii.filePath = 'https://120.48.32.121:444/wholesale' + ii.filePath

            // if (!ii.filePath.startWith('http')) {
            //   ii.filePath = window.location.origin + '/wholesale' + ii.filePath;
            // }


            if (ii.filePath.indexOf('http') === -1) {
              ii.filePath = 'https://www.xdyy100.com/wholesale' + ii.filePath
            }

            this.$set(ii, 'imgApplyStatus', '')
            this.$set(ii, 'imgEnlarge', false)
            this.$set(ii, 'srcList', [ii.filePath])
            this.dict.type.purchaser_apply_status.forEach(i => {
              if (i.value === ii.applyStatus) {
                this.$set(ii, 'status', i.label)
              }
            })
          })
        }
      })
    },
    // 审核图片
    SubmitExamine (r) {
      examinePurchaserImg(r.purchaserId, r.classificationId, { applyStatus: r.imgApplyStatus, failReason: r.textarea, id: r.id }).then(res => {
        console.log(res)
        if (res.code === 200) {
          this.$modal.msgSuccess(res.msg)
        }
      })
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange (selection) {
      this.ids = selection.map(item => item.purchaserId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    /** 新增/修改按钮操作 */
    handleEditTable (row) {
      //   const params = { pageNum: 1 };
      //   if (row) {
      //     params.goodsSku = {
      //       id: row.id,
      //       goodsId: row.goodsId,
      //       goodsName: row.goodsName
      //     };
      //   }
      //   const tabTitle = row ? "修改商品" : "新增商品";
      //   this.$tab.openPage(tabTitle, "/goods/goods-sku-edit/edit", params);
    },
    /** 导出按钮操作 */
    handleExport () {
      this.download(
        "purchaser/purchaser/export",
        {
          ...this.addDateRangeWithMap(this.queryParams, this.dateRange, "CreateTime")
        },
        `客户列表_${this.parseTime(new Date().getTime(), "{y}-{m}-{d}_{h}:{i}:{s}")}.xlsx`
      );
    },
    //打开审核窗口
    preview (row) {
      this.loading = true
      previewMaterials(row.purchaserId).then(response => {
        this.previewMaterial = response.data
        this.previewMaterialVisble = true
        this.loading = false
      })
    },
    goForReview (e) {
      this.currentMaterialRow = e
      this.currentExamineMaterialId = e.id
      this.auditingData = []
      if (e.config) {
        let config = JSON.parse(e.config.replace("\\", ""))
        for (const key in config) {
          this.$set(config[key], 'lineName', key)
          config[key].key = key
          this.auditingData.push(config[key])
          if (key === 'province') { this.province = config[key].value }
          if (key === 'city') { this.city = config[key].value }
          if (key === 'county') { this.county = config[key].value }
        }
        //排序
        this.auditingData = this.auditingData.sort(function (a, b) {
          return a['sortNum'] - b['sortNum'];
        })
      }
      this.auditingData.push({
        "title": "审核意见",
        "key": "failReason",
        "value": e.failReason,
        "control": "textarea"
      })
      console.log(this.auditingData)
      administrativeDivision().then(r => {
        this.administrativeProvince = this.handleTree(r.data, 'id')[0].children
        this.administrativeProvince.forEach(i => { if (i.id === this.province) this.administrativeCity = i.children })
        this.administrativeCity.forEach(i => { if (i.id === this.city) this.administrativeCounty = i.children })
      })

      this.auditingFilePath = e.filePath
      this.auditingTitle = "审核<" + e.classificationName + ">"
      this.failReason = ''
      this.auditingVisible = true
    },
    // 点击图片
    clickOriginal (row) {
      this.goForReview(row)
    },
    modifyAdministrative (e) {
      this.auditingData.forEach(i => {
        if (e.lineName === 'province') {
          this.administrativeCity = []
          this.administrativeCounty = []
          this.administrativeProvince.forEach(i => { if (i.id === e.value) this.administrativeCity = i.children })
          if (i.lineName === 'city') i.value = ''
          if (i.lineName === 'county') i.value = ''
        }
        if (e.lineName === 'city') {
          this.administrativeCounty = []
          this.administrativeCity.forEach(i => { if (i.id === e.value) this.administrativeCounty = i.children })
          if (i.lineName === 'county') i.value = ''
        }
      })
    },
    //审核单个资质
    materialVerify (applyStatus) {
      var value = {}
      var failReason = ''
      this.auditingData.forEach(material => {
        const key = material.key
        if (key == 'failReason') {
          failReason = material.value
        } else {
          value[key] = material.value
        }
      });

      var param = {
        value: JSON.stringify(value),
        failReason: failReason,
        applyStatus: applyStatus
      }
      const _this = this
      this.$modal.confirm('确认审核吗？').then(function () {
        materialExamine(_this.currentExamineMaterialId, param).then(response => {
          _this.currentMaterialRow.applyStatus = applyStatus
          _this.$modal.msgSuccess("审核成功")
          _this.auditingVisible = false
        })
      })
    },
    /** 修改密码/登录账号 操作 */
    handleEditTable (row) {
      // const params = { pageNum: 1 };
      // if (row) {
      //   params.goodsSku = {
      //     id: row.id,
      //     goodsId: row.goodsId,
      //     goodsName: row.goodsName
      //   };
      // }
      // const tabTitle = row ? "修改商品" : "新增商品";
      // this.$tab.openPage(tabTitle, "/goods", params);

      this.modifyPassword = ''
      this.modifyAccount = ''
      this.modifyPhone = ''
      this.buyerName = ''

      this.memberId = row.memberId
      this.purchaserId = row.purchaserId
      this.businessRange2 = ''
      this.businessRangeVisible2 = true
    },
    clickBusiness3 () {
      let that = this
      this.$modal.confirm('确认修改吗？').then(function () {
        return changeAccount(that.purchaserId, { username: that.modifyAccount, mobile: that.modifyAccount, name: that.buyerName })
        .then(res=>{
          that.getList()
        })
      }).then(() => {
        this.$modal.msgSuccess("成功")
        this.businessRangeVisible2 = false
      })
    },
    clickBusiness2 () {
      let that = this
      this.$modal.confirm('确认修改吗？').then(function () {
        return changePassword(that.purchaserId, that.memberId, { password: that.modifyPassword })
      }).then(() => {
        this.$modal.msgSuccess("成功")
        this.businessRangeVisible2 = false
      })
    },
    openTemporaryPwdView(row){
      this.currentRow = row
      this.openTemporaryPwdFlag = true
      this.refreshTemporaryPwd()
    },
    //刷新临时密码
    refreshTemporaryPwd () {
      refreshTmpPwd(this.currentRow.memberId).then(res=>{
        this.temporaryPwd = res.data
      })
    },
    // 更多操作触发
    handleCommand (command, row) {
      switch (command) {
        case "openPreview":
          this.preview(row)
          break;
        case "openBusinessContent":
          this.businessContent(row);
          break;
        case "openSeeCertificate":
          this.seeCertificate(row);
          break;
        case "openHandleEditTable":
          this.handleEditTable(row);
          break;
        case "handleTemporaryPwd":
          this.openTemporaryPwdView(row);
          break;
        case "deleteHandle":
          this.deleteClick(row);
          break;
        default:
          break;
      }
    },
    // 经营范围
    businessContent (row) {
      this.businessRangeVisible = true
      this.businessRange = row.business
      this.purchaserId = row.purchaserId
    },

    //  修改经营范围
    clickBusiness () {
      let that = this
      this.$modal.confirm('确认修改吗？').then(function () {
        return updateBusiness(that.purchaserId, { business: that.businessRange })
      }).then(() => {
        this.businessRangeVisible = false
        this.$modal.msgSuccess("成功")
        this.getList()
      })

      // updateBusiness(this.purchaserId, { business: this.businessRange }).then(res => {
      //   if (res.code === 200) {
      //     console.log(res)
      //   }
      // })
    },
    //一键审核客户资质
    openExamineView(row){
      let that = this
      this.$modal.confirm('确认通过客户上传的资质吗？').then(function () {
        return autoExamine(row.purchaserId, { beforeApplyStatus: row.applyStatus, afterApplyStatus: 'REVIEW' })
        .then(res=>{
          that.getList()
        })
      }).then(() => {
        this.$modal.msgSuccess("成功")
      })
    },
  }
}
</script>

<style lang="scss" scoped>
::v-deep .el-dialog {
  top: 0;
  .list {
    display: flex;
    flex-flow: row wrap;
    .item {
      display: flex;
      flex-flow: row wrap;
      border: 1px solid #f5f5f5;
      padding: 5px;
      img {
        width: 200px;
        height: 200px;
      }
      .imgEnlarge {
        width: 700px;
        height: 700px;
        position: absolute;
        z-index: 111;
        top: 0;
      }
      .status {
        display: flex;
        flex-flow: column nowrap;
        p {
          padding: 0 10px;
        }
        .el-select {
          width: 150px;
          margin: 5px 10px 10px;
        }
        textarea {
          width: 150px;
          height: 50px;
          resize: none;
          margin: 0 10px;
          outline: none;
        }
        .el-button {
          width: 150px;
          margin: 10px 10px 0 10px;
        }
      }
    }
  }
}

.content {
  display: flex;
  min-height: 600px;
  .preview {
    flex: 1;
    margin-right: 20px;
    border: 1px solid red;
  }
  ::v-deep .el-descriptions {
    flex: 1;
  }

  ::v-deep .el-descriptions-item__cell {
    padding: 2px 10px;
    text-align: center;
  }

  ::v-deep .el-input,
  ::v-deep .el-select {
    width: 100%;
  }
  ::v-deep .el-descriptions-item__label {
    width: 150px;
  }
}
</style>
